//
//  NSString+Methods.m
//  ChatForHot
//
//  Created by FLY on 2018/10/9.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "NSString+Methods.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (Methods)

NSString *systemTimes(){
    NSInteger times = [[NSDate date] timeIntervalSince1970];
    return @(times).stringValue;
}

NSString *md5_32bit(NSString *value){
    const char *original_str = [value UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(original_str, (int)strlen(original_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
        [hash appendFormat:@"%02X", result[i]];
    
    return [hash lowercaseString];
}
NSString *md5_16bit(NSString *value){
    const char *original_str = [value UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(original_str, (int)strlen(original_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 4; i < 12; i++)
        [hash appendFormat:@"%02X", result[i]];
    
    return [hash lowercaseString];
}

- (NSString *)HOTCHATmd5WithKey:(NSString *)key{
    NSString *str1 = [self stringByAppendingString:key];
    NSString *str2 = md5_32bit(str1);
    NSString *str3 = md5_16bit(str2);
    return [str2 stringByAppendingString:str3];
}
+ (NSString *)HOTCHATchatTypeForType:(NSInteger)chatType{
    if (chatType == HOTCHATFRIEND_CHAT) {
        return NSLocalizedString(@"StrN052", nil);
    }
    if (chatType == HOTCHATYUE_CHAT) {
        return NSLocalizedString(@"StrN053", nil);
    }
    return nil;
}
@end
